﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.IO;

namespace BDSim
{
    public class TrackSetMaxValueViewModel : INotifyPropertyChanged
    {
        #region  属性

        #region 极限值设定

        /// <summary>
        /// 直线动态限值

        /// </summary>
        private LineRunLimt _LineRunLimtValue = new LineRunLimt() { MaxVel = 200.0, MaxAccelarate = 50.0, MaxAcceAcce = 500 };

        public LineRunLimt LineRunLimtValue
        {
            get { return _LineRunLimtValue; }
            set { _LineRunLimtValue = value; NotifyPropertyChanged("LineRunLimtValue"); }
        }
        /// <summary>
        /// 航向角限值

        /// </summary>
        private OritatonAngleLimt _OritatonAngleLimtValue = new OritatonAngleLimt() { MaxAngleVel = 1, MaxAngleAccelarate = 10.0, MaxAngleAcceAcce = 100 };

        public OritatonAngleLimt OritatonAngleLimtValue
        {
            get { return _OritatonAngleLimtValue; }
            set { _OritatonAngleLimtValue = value; NotifyPropertyChanged("OritatonAngleLimtValue"); }
        }
        /// <summary>
        /// 俯仰角限值

        /// </summary>
        private PitchLimt _PitchLimtValue = new PitchLimt() { MaxAngle = 1.5707963267949, MaxAngleVel = 1, MaxAngleAccelarate = 10, MaxAngleAcceAcce = 100 };

        public PitchLimt PitchLimtValue
        {
            get { return _PitchLimtValue; }
            set { _PitchLimtValue = value; NotifyPropertyChanged("PitchLimtValue"); }
        }
        /// <summary>
        /// 横滚角限值

        /// </summary>
        private LandRollLimt _LandRollLimtValue = new LandRollLimt() { MaxAngle = 3.14159265358979, MaxAngleVel = 1, MaxAngleAccelarate = 10, MaxAngleAcceAcce = 100 };

        public LandRollLimt LandRollLimtValue
        {
            get { return _LandRollLimtValue; }
            set { _LandRollLimtValue = value; NotifyPropertyChanged("LandRollLimtValue"); }
        }
        /// <summary>
        /// 侧向动态限值

        /// </summary>
        private LateralLimt _LateralLimtValue = new LateralLimt() { MaxAccelarate = 69.3092, MaxAcceAcce = 500 };

        public LateralLimt LateralLimtValue
        {
            get { return _LateralLimtValue; }
            set { _LateralLimtValue = value; NotifyPropertyChanged("LateralLimtValue"); }
        }

        private int _SimStepSelectedIndex = 4;

        public int SimStepSelectedIndex
        {
            get { return _SimStepSelectedIndex; }
            set { _SimStepSelectedIndex = value; NotifyPropertyChanged("SimStepSelectedIndex"); }
        }
        private int _OutStepSelectedIndex = 4;

        public int OutStepSelectedIndex
        {
            get { return _OutStepSelectedIndex; }
            set { _OutStepSelectedIndex = value; NotifyPropertyChanged("OutStepSelectedIndex"); }
        }
        /// <summary>
        /// 仿真步长
        /// </summary>
        private int[] _SimStepArry = new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

        public int[] SimStepArry
        {
            get { return _SimStepArry; }
            set { _SimStepArry = value; }
        }
        /// <summary>
        /// 输出步长
        /// </summary>
        private int[] _OutStepArry = new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

        public int[] OutStepArry
        {
            get { return _OutStepArry; }
            set { _OutStepArry = value; }
        }

        #endregion
        #endregion

        #region 方法
        public void SaveLimitValueFile(string FilePath, string FileName)
        {
            FilePath += "lim";
            FileName += "lim";
            try
            {
                string strTemp;
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Line_spend_max.ToString(), LineRunLimtValue.MaxVel);
                File.AppendAllText(FilePath, strTemp);
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Line_acc_max.ToString(), LineRunLimtValue.MaxAccelarate);
                File.AppendAllText(FilePath, strTemp);
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Line_jerk_max.ToString(), LineRunLimtValue.MaxAcceAcce);
                File.AppendAllText(FilePath, strTemp);
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Lateral_acc_max.ToString(), LateralLimtValue.MaxAccelarate);
                File.AppendAllText(FilePath, strTemp);
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Lateral_jerk_max.ToString(), LateralLimtValue.MaxAcceAcce);
                File.AppendAllText(FilePath, strTemp);
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Yaw_rat_max.ToString(), OritatonAngleLimtValue.MaxAngleVel);
                File.AppendAllText(FilePath, strTemp);
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Yaw_acc_max.ToString(), OritatonAngleLimtValue.MaxAngleAccelarate);
                File.AppendAllText(FilePath, strTemp);
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Yaw_jerk_max.ToString(), OritatonAngleLimtValue.MaxAngleAcceAcce);
                File.AppendAllText(FilePath, strTemp);
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Pitch_angle_max.ToString(), PitchLimtValue.MaxAngle);
                File.AppendAllText(FilePath, strTemp);
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Pitch_rat_max.ToString(), PitchLimtValue.MaxAngleVel);
                File.AppendAllText(FilePath, strTemp);
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Roll_acc_max.ToString(), PitchLimtValue.MaxAngleAccelarate);
                File.AppendAllText(FilePath, strTemp);
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Pitch_jrek_max.ToString(), PitchLimtValue.MaxAngleAcceAcce);
                File.AppendAllText(FilePath, strTemp);
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Roll_angle_max.ToString(), LandRollLimtValue.MaxAngle);
                File.AppendAllText(FilePath, strTemp);
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Roll_rate_max.ToString(), LandRollLimtValue.MaxAngleVel);
                File.AppendAllText(FilePath, strTemp);
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Roll_acc_max.ToString(), LandRollLimtValue.MaxAngleAccelarate);
                File.AppendAllText(FilePath, strTemp);
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Roll_jerk_max.ToString(), LandRollLimtValue.MaxAngleAcceAcce);
                File.AppendAllText(FilePath, strTemp);
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Simustep.ToString(), SimStepSelectedIndex);
                File.AppendAllText(FilePath, strTemp);
                strTemp = string.Format("{0},{1}\n", LimTrackNameFileSave.Outstep.ToString(), OutStepSelectedIndex);
                File.AppendAllText(FilePath, strTemp);


            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show("保存限值设定文件出错！");
            }
        }
        #endregion

        #region 定义命令及实现

        private SimpleCommand _CmdSaveLimtValue;//保存

        public SimpleCommand CmdSaveLimtValue
        {
            get { return _CmdSaveLimtValue; }
            set { _CmdSaveLimtValue = value; }
        }

        private SimpleCommand _CmdCancelLimtValue;//取消

        public SimpleCommand CmdCancelLimtValue
        {
            get { return _CmdCancelLimtValue; }
            set { _CmdCancelLimtValue = value; }
        }

        void SaveLimtValue()
        {

        }

        void CancelLimtValue()
        {

        }

        #endregion

        #region///PropertyChanged接口
        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string Info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(Info));
            }
        }
        #endregion
    }
}
